/*
 * @FilePath: /data-and-structure-lv/10/stack.c
 * @Brief: 
 * @Version: 1.0
 * @Date: 2021-12-26 10:42:02
 * @Author: zsk
 * @Copyright: open source
 * @LastEditors: zsk
 * @LastEditTime: 2021-12-26 11:01:57
 */
#include <stdio.h>

#define N 1024
typedef int ElementType;

typedef struct Stack_Tag
{
    ElementType s[N];
    int top;
} Stack;

int stack_empty(Stack *s)
{
    if (s->top == -1)
        return 1;
    else
        return 0;
}

void push(Stack *s, ElementType x)
{
    s->top += 1;
    s->s[s->top] = x;
}

ElementType pop(Stack *s)
{
    if (stack_empty(s))
    {
        /* code */
        printf("underflow\n");
        return -1;
    }
    else
    {
        s->top -= 1;
        return s->s[s->top + 1];
    }
}

void main()
{
    Stack s = {.top = -1};
    Stack *sp = &s;
    for (int i = 0; i < N; i++)
    {
        push(sp, i);
    }

    for (int i = 0; i < N+1; i++)
    {
        ElementType x = pop(sp);
        printf("%d ", x);
    }
    printf("\n");
}